package com.kaka.springboot.order.rabbitmq.producer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class TTLRabbitmqConfiguration {
    //声明交换机
    @Bean
    public DirectExchange ttlDirectExchange(){

        return new DirectExchange("ttl_order_exchange",true,false);
    }

    //声明队列 给队列设置过期时间
    @Bean
    public Queue directTTLQueue(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-message-ttl",5000);//这里一定是int
        return new Queue("ttl.direct.queue",true,false,false,map);
    }

    //具体消息
    @Bean
    public Queue directTTLMessageQueue(){
        return new Queue("ttl.message.direct.queue",true);
    }

    //完成交换机和队列绑定
    @Bean
    public Binding directTTLBinding(){
        return BindingBuilder.bind(directTTLQueue()).to(ttlDirectExchange()).with("ttl");
    }

    @Bean
    public Binding directMsgBinding(){
        return BindingBuilder.bind(directTTLMessageQueue()).to(ttlDirectExchange()).with("ttlmessage");
    }
}